package com.yike.user.controller;

import com.yike.user.entity.GoodsCount;
import com.yike.user.service.GoodsCountService;
import lombok.extern.slf4j.Slf4j;
import com.yike.user.param.GoodsCountPageParam;
import com.yike.common.base.BaseController;
import com.yike.common.api.ApiResult;
import com.yike.common.pagination.Paging;
import com.yike.common.log.Module;
import com.yike.common.log.OperationLog;
import com.yike.common.enums.OperationLogType;
import com.yike.common.api.Add;
import com.yike.common.api.Update;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 商品销售统计 控制器
 *
 * @author Sakura
 * @since 2024-11-13
 */
@Slf4j
@RestController
@RequestMapping("/goodsCount")
@Module("user")
@Api(value = "商品销售统计API", tags = {"商品销售统计"})
@ApiIgnore
public class GoodsCountController extends BaseController {

    @Autowired
    private GoodsCountService goodsCountService;

    /**
     * 添加商品销售统计
     */
    @PostMapping("/add")
    @OperationLog(name = "添加商品销售统计", type = OperationLogType.ADD)
    @ApiOperation(value = "添加商品销售统计", response = ApiResult.class)
    public ApiResult<Boolean> addGoodsCount(@Validated(Add.class) @RequestBody GoodsCount goodsCount) throws Exception {
        boolean flag = goodsCountService.saveGoodsCount(goodsCount);
        return ApiResult.result(flag);
    }

    /**
     * 修改商品销售统计
     */
    @PostMapping("/update")
    @OperationLog(name = "修改商品销售统计", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改商品销售统计", response = ApiResult.class)
    public ApiResult<Boolean> updateGoodsCount(@Validated(Update.class) @RequestBody GoodsCount goodsCount) throws Exception {
        boolean flag = goodsCountService.updateGoodsCount(goodsCount);
        return ApiResult.result(flag);
    }

    /**
     * 删除商品销售统计
     */
    @PostMapping("/delete/{id}")
    @OperationLog(name = "删除商品销售统计", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除商品销售统计", response = ApiResult.class)
    public ApiResult<Boolean> deleteGoodsCount(@PathVariable("id") Long id) throws Exception {
        boolean flag = goodsCountService.deleteGoodsCount(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取商品销售统计详情
     */
    @GetMapping("/info/{id}")
    @OperationLog(name = "商品销售统计详情", type = OperationLogType.INFO)
    @ApiOperation(value = "商品销售统计详情", response = GoodsCount.class)
    public ApiResult<GoodsCount> getGoodsCount(@PathVariable("id") Long id) throws Exception {
        GoodsCount goodsCount = goodsCountService.getById(id);
        return ApiResult.ok(goodsCount);
    }

    /**
     * 商品销售统计分页列表
     */
    @PostMapping("/getPageList")
    @OperationLog(name = "商品销售统计分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "商品销售统计分页列表", response = GoodsCount.class)
    public ApiResult<Paging<GoodsCount>> getGoodsCountPageList(@Validated @RequestBody GoodsCountPageParam goodsCountPageParam) throws Exception {
        Paging<GoodsCount> paging = goodsCountService.getGoodsCountPageList(goodsCountPageParam);
        return ApiResult.ok(paging);
    }

}

